#include "vector3d.h"

vector3d::vector3d(float _x, float _y, float _z)
{
	x=_x;
	y=_y;
	z=_z;
}

vector3d::vector3d(void){
	x=y=z=0;
}

vector3d::vector3d(const vector3d& v){
    x=v.x;
    y=v.y;
    z=v.z;
}

float vector3d::dot(vector3d& v){
	return x * v.x + y * v.y + z * v.z;
}

vector3d vector3d::cross(vector3d& v){
	return vector3d(y * v.z - v.y * z, z * v.x - v.z * x, x * v.y - v.x * y);
}

vector3d vector3d::unit(){
float m=mag();
return vector3d(x/m, y/m, z/m);
}

vector3d vector3d::operator~(){
	return unit();
}

vector3d vector3d::operator*(float k){
	return vector3d(x*k,y*k,z*k);
}

vector3d vector3d::operator/(float k){
	return vector3d(x/k,y/k,z/k);
}


vector3d vector3d::operator+(vector3d& v){
	return vector3d(x+v.x,y+v.y,z+v.z);
}

vector3d vector3d::operator-(vector3d& v){
	return vector3d(x-v.x,y-v.y,z-v.z);
}

vector3d vector3d::operator-(){
	return vector3d(-x, -y, -z);
}

float vector3d::mag(){
	return sqrt(x*x+y*y+z*z);
}

vector3d vector3d::rotateX(float angle){
    this->x=this->x;
    this->y=this->y*cos(angle) - this->z*sin(angle);
    this->z=this->y*sin(angle) + this->z*cos(angle);
    return (*this);
}

vector3d vector3d::rotateY(float angle){
    this->x=this->x*cos(angle) + this->z*sin(angle);
    this->y=this->y;
    this->z=-this->x*sin(angle) + this->z*cos(angle);
    return (*this);
}

vector3d vector3d::rotateZ(float angle){
    this->x=this->x*cos(angle) - this->y*sin(angle);
    this->y=this->x*sin(angle) + this->y*cos(angle);
    this->z=this->z;
    return (*this);
}

vector3d::~vector3d(void){
}
